home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 104_01 / function.asm < prev    next >
Assembly Source File  |  1980-01-01  |  3KB  |  140 lines

  1.     title    'string assebmle function for BDS C'
  2.     page    60
  3. ;
  4.  
  5.     maclib    bds
  6.     maclib    cmac
  7. ;
  8. ;
  9.     direct
  10.     define    STRLEN
  11.     define    STRCPY
  12.     define    STRCAT
  13.     define    STRPOS
  14.     enddir
  15. ;
  16.     page
  17. ;
  18. ;    strlen
  19. ;
  20. ;    return lenght of string
  21. ;
  22.     prelude    strlen
  23. ;
  24.  
  25. strlen:
  26.     call    arghak        ;get arg list
  27.     lhld    arg1        ;get point to string
  28.     xchg            ;put address in de
  29.     lxi    h,0        ;put a zero in hl (length)
  30. strlen1:
  31.     ldax    d        ;get value of this character
  32.     ora    a        ;check to see if zero
  33.     rz            ;if zero end of string return
  34.     inx    h        ;add 1 to string lenght
  35.     inx    d        ;add 1 to pointer to string
  36.     reloc    jmp,strlen1    ;check next character
  37. ;
  38.     postlude strlen
  39. ;
  40. ;
  41. ;
  42.     prelude    strcpy
  43. ;
  44. strcpy:
  45.     call    arghak        ;get arg list
  46.     lhld    arg1        ;get address of where to save string
  47.     xchg            ;put address in de
  48.     lhld    arg2        ;get address of string to copy
  49. strcpy1:
  50.     mov    a,m        ;get value from source string
  51.     stax    d        ;save character a object string
  52.     ora    a        ;check to see if done
  53.     rz            ;if zero done return to caller
  54.     inx    h        ;add 1 to source pointer
  55.     inx    d        ;add 1 to object pointer
  56.     reloc    jmp,strcpy1    ;down till end of string
  57. ;
  58.     postlude strcpy
  59. ;
  60. ;
  61. ;
  62.     prelude    strcat
  63. strcat:
  64.     call    arghak    ;get parm list
  65.     lhld    arg1    ;get address of frist parm
  66.     xchg        ;put it in hl
  67.     lhld    arg2    ;get second parm
  68. strcat1:
  69.     ldax    d        ;get byte to see if zero
  70.     ora    a        ;set status flags
  71.     reloc    jz,strcat2    ;end of string 1 
  72.     inx    d        ;add 1 to pointer
  73.     reloc    jmp,strcat1    ;loop till end of string 1
  74. strcat2:
  75.     mov    a,m        ;get char for source string
  76.     stax    d        ;save at end of second string
  77.     ora    a        ;check to see if zero
  78.     rz            ;return if end of string 2
  79.     inx    h        ;add 1 to source pointer
  80.     inx    d        ;add 1 to object pointer
  81.     reloc    jmp,strcat2    ;loop till end of source string
  82.     postlude strcat
  83. ;
  84. ;
  85. ;
  86.     prelude    strpos
  87. ;
  88. strpos:
  89.     call    arghak        ;get parm list
  90.     push    b        ;save c stack on machine stack
  91.     lhld    arg1        ;get string that we are searching in
  92.     xchg            ;put address in de
  93.     lxi    b,0        ;zero postion 
  94. strpos1:
  95.     lhld    arg2        ;get address of search for string
  96. strpos2:
  97.     ldax    d        ;get character to check 
  98.     ora    a        ;check to see if end of string 1
  99.     reloc    jz,strpos4    ;end of string arg2 is not inside of arg1
  100.     inx    b        ;add 1 to postion
  101.     inx    d        ;add 1 top pointer of arg1
  102.     cmp    m        ;check to see if a match on first char
  103.     reloc    jnz,strpos2    ;loop till fisrt character match
  104.     push    d        ;save current postion on stack
  105.     dcx    d        ;move pointer back one
  106. strpos3:
  107.     inx    h        ;add 1 to arg1
  108.     inx    d        ;add 1 to arg2
  109.     mov    a,m        ;check to see if end of arg2
  110.     ora    a        ;see if zero 
  111.     reloc    jz,strpos5    ;end of arg2 match found 
  112.     ldax    d        ;get arg1
  113.     cmp    m        ;check to see if match
  114.     reloc    jz,strpos3    ;loop to end of string or nomatch
  115.     pop    d        ;remove search address from stack
  116.     reloc    jmp,strpos1    ;loop till end of arg1
  117. strpos4:
  118.     pop    b        ;restore c stack pointer
  119.     lxi    h,0        ;arg2 not found in arg1
  120.     ret
  121. strpos5:
  122.     mov    h,b        ;arg2 found in arg1
  123.     mov    l,c
  124.     pop    d        ;remove junk from stack
  125.     pop    b        ;restore b stack pointer
  126.     ret
  127. ;
  128. ;
  129.     postlude strpos
  130.     end
  131. lude strpos
  132.     end
  133. 
  134. end
  135. 
  136.     ret
  137. ;
  138. ;
  139.     postlude strpos
  140.     end